//
//  CZMainViewController.swift
//  CZWeibo
//
//  Created by 左凯旭 on 16/8/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

       //设置自定义tabbar
        let tabbar = CZTabBar()
        
        tabbar.czdelegate = self
        
        //用kvc给只读属性赋值
        setValue(tabbar, forKey: "tabBar")
        
        
        addChildViewController(CZHomeViewController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(CZMessageViewController(), imgName: "tabbar_message_center", title: "信息")
        addChildViewController(CZDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(CZProfileViewController(), imgName: "tabbar_profile", title: "我们")
        
    }


    
    func addChildViewController(vc:UIViewController,imgName:String,title:String){
        
//        vc.navigationItem.title = "首页"
//        vc.tabBarItem.title = "首页"
        
        //可以写成一个
        vc.title = title
        //设置title样式
    vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:AppThemeColor], forState: UIControlState.Selected)
        
        
        vc.tabBarItem.image = UIImage(named: imgName)
        
        // AlwaysOriginal 图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
}


extension CZMainViewController:CZTabBarDelegate{
    
    func tabBarButtonClick() {
//        print("撰写按钮的点击")
        
        if !CZUserAccountViewModel.shareTools.isLogin {
            print("请登录")
            return
        }
        
        //跳转控制器
        let composeVC = CZComposeViewController()
        
        self.presentViewController(UINavigationController(rootViewController: composeVC), animated: true, completion: nil)
    }
}




